package com.boxedinsoftware.ePost;

import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.Toast;

/** Class Must extends with Dialog */
/** Implement onClickListener to dismiss dialog when OK Button is pressed */
public class courseChooser extends Dialog implements OnClickListener {
	Button okButton;
	Button cancelButton;
	
	String[] year = {"2009-10" , "2010-11" , "2011-12"};
	String[] term = {"F" , "W" , "S"};
	String[] course = {"2031" , "2001" , "2021"};
	
	
	protected Spinner cur1;
	protected Spinner cur2;
	protected Spinner cur3;
	
	public courseChooser(Context context) {
		super(context);
		/** 'Window.FEATURE_NO_TITLE' - Used to hide the title */
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		/** Design the dialog in main.xml file */
		setContentView(R.layout.addcourselayout);
		okButton = (Button) findViewById(R.id.OkButton);
		okButton.setOnClickListener(this);
		cancelButton = (Button)findViewById(R.id.Button01);
		cancelButton.setOnClickListener(this);
		
		 cur1 = (Spinner)findViewById(R.id.Spinner01);
		 cur2 = (Spinner)findViewById(R.id.Spinner02);
		 cur3 = (Spinner)findViewById(R.id.Spinner03);
		
		
		 	ArrayAdapter<String> adapter1 = new ArrayAdapter<String>( context, android.R.layout.simple_spinner_item);

			adapter1.add(new String(year[0]));
			adapter1.add(new String(year[1]));
			adapter1.add(new String(year[2]));
			cur1.setAdapter(adapter1);
			
			ArrayAdapter<String> adapter2 = new ArrayAdapter<String>( context, android.R.layout.simple_spinner_item);

			adapter2.add(new String(term[0]));
			adapter2.add(new String(term[1]));
			adapter2.add(new String(term[2]));
			cur2.setAdapter(adapter2);
			
			ArrayAdapter<String> adapter3 = new ArrayAdapter<String>( context, android.R.layout.simple_spinner_item);

			adapter3.add(new String(course[0]));
			adapter3.add(new String(course[1]));
			adapter3.add(new String(course[2]));
			cur3.setAdapter(adapter3);
			
			
		
	}

	public void onClick(View v) {
		/** When OK Button is clicked, dismiss the dialog */
		if (v == okButton)
		{
			Toast.makeText(this.getContext(), "Year : " + year[cur1.getSelectedItemPosition()] + " Term : " + term[cur2.getSelectedItemPosition()] + " Course : " + course[cur3.getSelectedItemPosition()], Toast.LENGTH_LONG).show();
			dismiss();
		}
		else if ( v == cancelButton)
			dismiss();
	}

}
